import socket
import time

#socket.SOCK_DGRAM：基于数据报-UDP
mysocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
mysocket.connect(('127.0.0.1', 2425))

# IPMSG的报文格式: 版本号:包编号:发送者姓名:发送者主机名:命令字:消息内容:附加信息(非必须)
packetID = str(time.time())
name = '大美'
host = 'localhost'
command = str(0x00000020)   #0x00000020表示发送消息
content = 'This is the message from Python'
#   构建消息体
message = '1.0:' + packetID + ':' + name + ':' + host + ':' + command + ':' + content

mysocket.send(message.encode('GBK'))    #编码格式是GBK
mysocket.close()
